package com.jayzers.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jayzers.bean.AdminInfoBean1;
import com.jayzers.service.impl.LoginServiceImpl;
import com.jayzers.utils.MyUtils;

/**
 * Servlet implementation class AddAddress
 */
@WebServlet("/AddressAction")
public class AddAddress extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		// 业务逻辑处理
		// 1.接收表单数据t

		AdminInfoBean1 adminC = MyUtils.convertFormData2Bean(request, AdminInfoBean1.class);
		System.out.println("对象数据为:" + adminC.toString());

		// 2.调用service层进行数据保存
		int i = MyUtils.getInstance(LoginServiceImpl.class).saveOrUpdateAdminInfo(adminC);
		System.out.println("i:" + i);
		// 3、根据保存处理结果进行页面转发
		if (i > 0) {
			// 保存成功
			response.sendRedirect("message.jsp");
		} else {
			// 保存失败
			response.sendRedirect("address.jsp");
		}

	}
}
